package com.czkspringcloud.controller;

import com.czkspringcloud.config.MyLinkedBlockingQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/12/20 18:06
 */
@RestController
// 增加刷新功能
@RefreshScope
public class ConfigClientController {
    @Value("${config.info}")
    private String configInfo;

    @GetMapping("/configInfo")
    public String getConfigInfo() {
        return configInfo;
    }

    /**
     * 由于spring的单例，模式，这里注入的也会跟随变化
     */
    @Autowired
    private ThreadPoolExecutor threadPoolExecutor;

    @GetMapping("/look")
    public Map<String, Integer> getInformations() {
        Map<String, Integer> map = new HashMap<>();
        map.put("coreSize", threadPoolExecutor.getCorePoolSize());
        map.put("maxSize", threadPoolExecutor.getMaximumPoolSize());
        map.put("queueSize", ((MyLinkedBlockingQueue) threadPoolExecutor.getQueue()).getCapacity());
        return map;
    }
}
